package com.models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import lombok.Getter;
import lombok.Setter;

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames={"folder", "ownerUser", "viewerUser"}))
public class Shared {
	
	public static final String cFolder = "folder";
	public static final String cPath = "path";
	public static final String cOrgPath = "orgPath";
	public static final String cOwner = "ownerUser";
	public static final String cViewer = "viewerUser";

	@Id @GeneratedValue 
	@Getter private int id;
	
	@Column(name=cFolder, nullable=false) 
	@Getter @Setter private String folder;

	@Column(name=cPath, nullable=false)
	@Getter @Setter private String path;

	@Column(name=cOrgPath, nullable=false)
	@Getter @Setter private String orgPath;
	
	@ManyToOne(targetEntity=User.class) 
	@JoinColumn(name=cOwner, referencedColumnName="id") 
	@Getter @Setter private User ownerUser;
	
	@ManyToOne(targetEntity=User.class)
	@JoinColumn(name=cViewer, referencedColumnName="id") 
	@Getter @Setter private User viewerUser;	
		
	public Shared() {
		// TODO Auto-generated constructor stub
	}
	
	public Shared(String folder, String path, String orgPath, User ownerUser, User viewerUser) {
		this.folder = folder;
		this.path = path;
		this.orgPath = orgPath;
		this.ownerUser = ownerUser;
		this.viewerUser = viewerUser;
	}
	
}
